package Iostart;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.OutputStreamWriter;

public class IoMainOne
{
	public static void main(String[] args)
	{
		System.out.println("========");
		readFile();
		writeFile();
		objectRead();
	}

	private static void objectRead()
	{
		ObjectInputStream fa = null;
		try
		{
			FileInputStream  fid = new FileInputStream("D:/a/c,txt");
//			InputStreamReader  fis = new InputStreamReader(fid);
			//字节转字符只能用InputStreamReader来转
			BufferedInputStream ff = new BufferedInputStream(fid);
			fa = new ObjectInputStream(ff);
		} catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally 
		{
			try
			{
				if(fa != null) 
				{
					fa.close();
					fa = null;
				}
			} catch (Exception e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}

	private static void writeFile()
	{
		BufferedWriter fif = null;
		try
		{
			File file = new File("D:/a/b.txt");
			FileOutputStream fis = new FileOutputStream(file);
			OutputStreamWriter fid = new OutputStreamWriter(fis);
			fif = new BufferedWriter(fid); 
			fif.write("李善壮我是你大哥");
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		}catch (Exception e)
		{
			e.printStackTrace();
		}finally 
		{
			try
			{
				if(fif != null ) 
				{
					fif.close();
					fif = null;
				}
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}

	private static void readFile()
	{
		BufferedReader  fid = null;
		try
		{
			FileInputStream fof = new FileInputStream("D:/a/a.txt");
			InputStreamReader  fis = new InputStreamReader(fof,"GBK"); 
			fid = new BufferedReader(fis);
			String a = fid.readLine();
			System.out.println(a);
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		}catch (Exception e)
		{
			e.printStackTrace();
		}finally 
		{
			try
			{
				if(fid != null) 
				{
					fid.close();
					fid = null;
				}
			} catch (IOException e)
			{
				e.printStackTrace();
			}
			
		}
	}
}
